package com.xh.xyzp.config;

import com.baomidou.mybatisplus.extension.exceptions.ApiException;
import com.xh.xyzp.common.domain.vo.resp.ApiResult;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * @Author: xianghao
 * @Description:
 * @Date: 2024-10-04  00:15
 */
@ResponseBody
@ControllerAdvice
public class ExceptionConfig {

    @ExceptionHandler(value = ApiException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ApiResult<String> ApiException(ApiException exception){
        exception.printStackTrace();
        return ApiResult.fail(exception.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ApiResult<String> Exception(Exception exception){
        exception.printStackTrace();
        return ApiResult.fail("系统异常，请联系管理员：" + exception.getMessage());
    }
}
